#!usr/bin/node

const mysql = require('mysql2/promise');

let con;

(async()=>{
  con = await mysql.createConnection({
    host:'localhost',
    user:'root',
    password:'ddd',
    database:'todo'
  });
})();

async function getItems() {
  const sql = 'select * from tasks;'

  const [rows] = await con.query(sql);
  
  return JSON.stringify(rows);
}

async function insert(item) {
  const sql = `insert into tasks(task) values("${item}")`;

  await con.query(sql);
}

module.exports = {getItems,insert};

